#ifndef MODIFYWIDGET_H
#define MODIFYWIDGET_H

#include <QWidget>
#include <QDialog>
#include <QLineEdit>
#include <QRadioButton>
#include <QComboBox>
#include <QPushButton>
#include <QCalendarWidget>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>

namespace Ui {
class Widget;
}

class StudentModifyWidget : public QWidget
{
    Q_OBJECT

public:
    explicit StudentModifyWidget(QWidget *parent = nullptr);
    ~StudentModifyWidget();


private:
    void setupUI();
    void setID(const int &id);
    bool isFieldValid(QLineEdit* field, const QRegularExpression& regex);
    void checkFormValidity();
    void saveStudentInfo();
    void handleDateSelection(const QDate &date);
    void closeCalendar();
    bool connectToDatabase();
    void loadStudentData();

protected:
    bool eventFilter(QObject *obj, QEvent *event) override;

signals:
    void dataSaved();

public slots:
    void on_saveButton_clicked();
    void on_cancelButton_clicked();
    void on_calendarButton_clicked();


private:
    Ui::Widget *ui;
    QSqlDatabase db;
    int id;
    QCalendarWidget *calendar;

};

#endif // MODIFYWIDGET_H
